<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>

<html>
	<head>
		<title>项目收入结算</title>
	</head>
	<script type="text/javascript">
	var xmStatus = new Array("新建","未开工", "在建", "完工", "验收", "送审", "开票" ,"结算", "关闭"); 
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			$("#table").datagrid({
				title:"项目结算开票/收款",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/xm/listPageXMInMoneyBalance?type=0',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				]],
				columns:[[
					{title:'项目进度',field:'xm_progress_status',width:100,align:'center',formatter:function(value,rowData,rowIndex){
					    return xmStatus[value];
					}},
					{title:'所属部门',field:'admin_dept',width:100,align:'center'},
					{title:'项目编号',field:'xm_code',width:100,align:'center'},
					{title:'项目名称',field:'xm_name',width:200,align:'center'},
					{title:'收入审核状态',field:'xm_inmoney_balance_status',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(value==1){
							return "审核中";
						}else if(value==2){
							return "审核不通过";
						}else if(value==3){
							return "审核通过";
						}
						return "未提交审核";
					}},
					/**
					{title:'客户',field:'customer',width:120,align:'center'},
					{title:'专业分类',field:'specialty_type',width:100,align:'center'},
					{title:'管理员名称',field:'admin_name',width:100,align:'center'},
					{title:'开工时间',field:'start_time',width:100,align:'center'},
					{title:'绑定工单数量',field:'xm_gds_num',width:100,align:'center'},
					{title:'基础信息查看',field:'more',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='项目详情' onclick=\"javascript:viewXMData('"+rowData.id+"','"+rowData.xm_code+"','"+rowData.xm_name+"');\"/>";
					}},
					**/
					{title:'操作',field:'operation',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						$.ajax({
							type:'POST',
							async:false,
							url:'<%=contextPath %>/springMVC/xmFinance/hasXMEndInMoney?type=1&xm_id='+rowData.id,
							success:function(rtJson){
								if(rtJson == '0'){
									str =  "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-add' title='结算操作' onclick=\"javascript:addXMInMoneyBalance('"+rowData.id+"','"+rowData.xm_code+"','"+rowData.xm_name+"');\"/>";
								}else{
									if(rowData.xm_inmoney_balance_status == 0){
										//还没提交审核时，可以编辑
										str = "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-add' title='结算操作' onclick=\"javascript:addXMInMoneyBalance('"+rowData.id+"','"+rowData.xm_code+"','"+rowData.xm_name+"');\"/>&nbsp;&nbsp;"
												+"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"','"+rowData.xm_code+"','"+rowData.xm_name+"');\"/>";	
									}else{
										str = "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.XM_END_INMONEY_BALANCE_SHENPI%>")+"','"+rowData.id+"');\"/>&nbsp;&nbsp;"
												+"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看详情' onclick=\"javascript:viewData('"+rowData.id+"','"+rowData.xm_code+"','"+rowData.xm_name+"');\"/>";
									}
								}
							}
						});
						return str;
					}}
				]],
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				toolbar:"#tb",
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});

		function shenpi(obj,id,xm_code,xm_name){
	    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	      var flowBusinessUrl="<%=contextPath %>/springViews/xm/viewInMoneyBalance.jsp?xm_id="+id+"&xm_code="+xm_code+"&xm_name="+xm_name+"&isShow=1";
	      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.XM_END_INMONEY_BALANCE_SHENPI%>")+"&businessId="+id+"&isShow=1";
	      $(obj).hide();
	      $.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							$(obj).show();
						}
					});
	       
	    } 
		
		function addXMInMoneyBalance(id,xm_code,xm_name){
			openDialogResize("<%=contextPath %>/springViews/xm/inMoneyBalanceManage.jsp?xm_id="+id+"&xm_code="+xm_code+"&xm_name="+xm_name+"&callback=rtCallBack&isShow=0",1024, 800);
		}
		function  viewXMData(id,xm_code,xm_name){
		openDialogResize("<%=contextPath %>/springViews/xm/viewXm.jsp?xm_id="+id+"&xm_code="+xm_code+"&xm_name="+xm_name+"&callback=rtCallBack&isShow=0",1024, 800);
		}
		
		function  viewData(id,xm_code,xm_name){
			openDialogResize("<%=contextPath %>/springViews/xm/viewInMoneyBalance.jsp?xm_id="+id+"&xm_code="+xm_code+"&xm_name="+xm_name+"&callback=rtCallBack&isFlowShow=1",1000, 800);
	
		}

		function rtCallBack(){
			$('#table').datagrid('reload');
		}


		function doSearch()
		{
			var start_time=$('#start_time').datebox('getValue');  
			var end_time=$('#end_time').datebox('getValue');  
			var searchValue = $('#searchValue').val();
			var dept_id = $('#dept_id').combotree('getValue');
			$('#table').datagrid('load',{
				searchValue:searchValue,
				dept_id:dept_id,
				start_time:start_time,
				end_time:end_time
				
			});
		}
		</script>
		<body style="height: 97%">
			<div id="table" data-options="fit:true" ></div>
			<div id="tb" style="padding:3px;height:auto">
				<div align="right">
					<div style="display:none;">开始时间：<input id="start_time" name="start_time" class="easyui-datebox" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" /></div>
					选择部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">  
					项目编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="项目名称或编码" placeholder="项目名称或编码 "  />&nbsp;&nbsp; 
					<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
				</div>
			</div>
		</body>
	</html>
